package q2000_q2999;

/**
 * @Author: wzp
 * @CreateTime: 2024-09-24  10:16
 * @Description: 字符串中最多数目的子序列
 * @Version: 1.0
 */
public class q_2207 {
    public long maximumSubsequenceCount(String text, String pattern) {

        char[] patternArr = pattern.toCharArray();
        char[] textArr = text.toCharArray();
        char l=patternArr[0];
        char r=patternArr[1];
//        先统计数量
        int l_num=0;
        int r_num=0;
        int result=0;
        int sum=0;
        for (int i = 0; i < textArr.length; i++) {
            if(textArr[i]==r){
                result+=l_num;
                r_num++;
            }
            if(textArr[i]==l){
                l_num++;
            }

        }
        result+=l_num>r_num?l_num:r_num;
        return result;
    }

    public static void main(String[] args) {
        String text = "aaaaaa";
//        5 4 3 2 1 6    结果为21
        String pattern = "aa";
        System.out.println(new q_2207().maximumSubsequenceCount(text, pattern));
    }

}
